#define IOP 14
#define PWM 3

int val_new;
int val_old;
int clicks = 0;
int turns = 0;

void setup() {
    Serial.begin(115200);
    pinMode(IOP, INPUT);
    attachInterrupt(0, blink, RISING );
}

void loop() {
    analogWrite(PWM, 80);
    val_new = digitalRead(IOP);
    
    if(val_new != val_old) {
        if(clicks == 40) {
            clicks = 1;
            turns++;
            Serial.print("TURNS: ");
            Serial.println(turns);   
        }
        else clicks++;
        
        Serial.print("CLICKS: ");
        Serial.println(clicks);

        val_old = val_new;
    }
}
